package com.hpin.mlxteacher.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

/**
 * 通讯录bean
 * Created by Aaron on 16/1/19.
 */
public class AddressBean implements Parcelable {

    /**
     * contacts : [{"user":{"_id":"56c13bee99dc8715760e296f","phoneNum":"18310861283","imgUrl":"http://7xn7x2.com2.z0.glb.qiniucdn.com/2015-11-27/le9cmojl0nrjxsz5xiqo6i68ke9ra0h2_s","nickName":"小丽"},"topic":"15311280989;18310861283","_id":"56c1499a8ec8c02877a23bd3"},{"user":{"_id":"56bf25eb99dc8715760e2967","phoneNum":"18610915892","imgUrl":"http://7xn7x2.com2.z0.glb.qiniucdn.com//group/2016-01-25/v65fu9khaab7pbv51g1djcyah3fwdzbv4wjlvsac2mm81ci1ue5zmkr8phah1l31_s","nickName":"冯"},"topic":"15311280989;18610915892","_id":"56c59912f50fd0c663b14329"}]
     * code : 0
     * code_msg : 成功
     */
    public int code;
    public String code_msg;

    /**
     * user : {"_id":"56c13bee99dc8715760e296f","phoneNum":"18310861283","imgUrl":"http://7xn7x2.com2.z0.glb.qiniucdn.com/2015-11-27/le9cmojl0nrjxsz5xiqo6i68ke9ra0h2_s","nickName":"小丽"}
     * topic : 15311280989;18310861283
     * _id : 56c1499a8ec8c02877a23bd3
     */
    public List<ContactsEntity> contacts;

    public static class ContactsEntity implements Parcelable {

        /**
         * _id : 56c13bee99dc8715760e296f
         * phoneNum : 18310861283
         * imgUrl : http://7xn7x2.com2.z0.glb.qiniucdn.com/2015-11-27/le9cmojl0nrjxsz5xiqo6i68ke9ra0h2_s
         * nickName : 小丽
         */
        public UserEntity user;
        public String topic;
        public String _id;
        public boolean isSelect;
        public boolean hasAdded;

//        public static class UserEntity implements Parcelable {
//            public String _id;
//            public String phoneNum;
//            public String imgUrl;
//            public String nickName;
//
//            @Override
//            public int describeContents() {
//                return 0;
//            }
//
//            @Override
//            public void writeToParcel(Parcel dest, int flags) {
//                dest.writeString(this._id);
//                dest.writeString(this.phoneNum);
//                dest.writeString(this.imgUrl);
//                dest.writeString(this.nickName);
//            }
//
//            public UserEntity() {
//            }
//
//            protected UserEntity(Parcel in) {
//                this._id = in.readString();
//                this.phoneNum = in.readString();
//                this.imgUrl = in.readString();
//                this.nickName = in.readString();
//            }
//
//            public static final Creator<UserEntity> CREATOR = new Creator<UserEntity>() {
//                public UserEntity createFromParcel(Parcel source) {
//                    return new UserEntity(source);
//                }
//
//                public UserEntity[] newArray(int size) {
//                    return new UserEntity[size];
//                }
//            };
//        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeParcelable(this.user, 0);
            dest.writeString(this.topic);
            dest.writeString(this._id);
            dest.writeByte(isSelect ? (byte) 1 : (byte) 0);
            dest.writeByte(hasAdded ? (byte) 1 : (byte) 0);
        }

        public ContactsEntity() {
        }

        protected ContactsEntity(Parcel in) {
            this.user = in.readParcelable(UserEntity.class.getClassLoader());
            this.topic = in.readString();
            this._id = in.readString();
            this.isSelect = in.readByte() != 0;
            this.hasAdded = in.readByte() != 0;
        }

        public static final Creator<ContactsEntity> CREATOR = new Creator<ContactsEntity>() {
            public ContactsEntity createFromParcel(Parcel source) {
                return new ContactsEntity(source);
            }

            public ContactsEntity[] newArray(int size) {
                return new ContactsEntity[size];
            }
        };
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.code);
        dest.writeString(this.code_msg);
        dest.writeTypedList(contacts);
    }

    public AddressBean() {
    }

    protected AddressBean(Parcel in) {
        this.code = in.readInt();
        this.code_msg = in.readString();
        this.contacts = in.createTypedArrayList(ContactsEntity.CREATOR);
    }

    public static final Creator<AddressBean> CREATOR = new Creator<AddressBean>() {
        public AddressBean createFromParcel(Parcel source) {
            return new AddressBean(source);
        }

        public AddressBean[] newArray(int size) {
            return new AddressBean[size];
        }
    };
}
